// hash-worker.js
self.importScripts('https://cdnjs.cloudflare.com/ajax/libs/spark-md5/3.0.2/spark-md5.min.js')

self.onmessage = async (e) => {
    const { file } = e.data
    const spark = new SparkMD5.ArrayBuffer()
    const reader = new FileReader()

    reader.onload = (e) => {
        spark.append(e.target.result)
        const hash = spark.end()
        self.postMessage({ hash })
    }

    reader.readAsArrayBuffer(file)
}
